from keras.models import Sequential
from keras.layers import LSTM, Dense
import numpy as np

data_dim = 16
timesteps = 8
num_classes = 10

# 预期输入数据shape: (batch_size, timesteps, data_dim)
model = Sequential()
model.add(LSTM(32, return_sequences=True, input_shape=(timesteps, data_dim)))  # (None, 8, 32)
model.add(LSTM(32, return_sequences=True))      # (None, 8, 32)
model.add(LSTM(32))                             # (None, 32)
model.add(Dense(10, activation='softmax'))      # (None, 10)

model.compile(loss='categorical_crossentropy', optimizer='rmsprop', metrics=['accuracy'])
print(model.summary())
# 生成虚拟训练数据
x_train = np.random.random((1000, timesteps, data_dim))     # (1000, 8, 16)
y_train = np.random.random((1000, num_classes))

# 生成虚拟验证数据
x_val = np.random.random((100, timesteps, data_dim))
y_val = np.random.random((100, num_classes))

model.fit(x_train, y_train, batch_size=64, epochs=20, validation_data=(x_val, y_val))